<% layout("/layouts/micro.html"){ %>
<div class="childrenBody">
	<div class="kit-table">
		<form class="layui-form" lay-filter="kit-search-form">
			<div class="kit-table-header">
				<div class="kit-search-btns">
					<%if(shiro.hasPermission("wx:wxAccountFans:edit")){%>
					<!-- <a class="layui-btn layui-btn-normal addWxAccountFans_btn"><i class="layui-icon">&#xe608;</i>新增</a> -->
					<a class="layui-btn layui-btn-normal syncWxAccountFans_btn"><i class="layui-icon">&#xe608;</i>同步粉丝</a>
					<a class="layui-btn layui-btn-danger layui-btn-normal delAll_btn"><i class="layui-icon">&#xe640;</i>批量删除</a>
					<%}%>
					<div class="layui-input-inline">
						<select name="pubid" id="pubid" lay-filter="pubid">
							<option value="1" <%if(wxAccountFans.pubid=="1"){%>selected<%}%>>公众号1</option>
							<option value="2" <%if(wxAccountFans.pubid=="2"){%>selected<%}%>>公众号2</option>
						</select>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">性别:</label>
						<div class="layui-input-inline">
							<select name="sex" class="layui-input" id="sex">
								<option value="" >全部</option>
								<#options items="${@DictUtils.getDictList('sex')}" value="${wxAccountFans.sex!}"/>
							</select>
						</div>
					</div>
				</div>
				<div class="kit-search-inputs clearfix">
					<div class="kit-search-keyword">
						<input type="text" class="layui-input" id="keyword" name="keyword" placeholder="昵称" />
						<button class="search_btn" type="button"><i class="layui-icon">&#xe615;</i></button>
					</div>
				</div>
			</div>
		</form>
		<div class="kit-table-body">
			<table id="wxAccountFansList" lay-filter="wxAccountFansList"></table>

			<!--操作-->
			<script type="text/html" id="wxAccountFansListBar">
				<a class="layui-btn layui-btn-xs" lay-event="sendMessage">发送信息</a>
				<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
				<!--<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="look">预览</a>-->
			</script>
		</div>
	</div>
</div>
<script>
    layui.use(['form','layer','laydate','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;

        //新闻列表
        var tableIns = table.render({
            elem: '#wxAccountFansList',
            url : '${ctx}/wx/wxAccountFans/listAjax',
            cellMinWidth : 95,
            page : true,
            request: {
                pageName: 'pageNo', //页码的参数名称，默认：page
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            height : "full-80",
            limit : 15,
            limits : [10,15,20,25],
            id : "wxAccountFansListTable",
            cols : [[
                {type: "checkbox", fixed:"left", width:50},
                {field:'headimgurl', title: '头像',width:80,templet:function(d){
                        return '<img src="'+d.headimgurl+'" style="width: 28px;height:28px;border-radius: 50%;">'
                    }},
                {field:'nickname', title: '昵称'},
                {field:'sexDesc', title: '性别描述'},
                {field:'country', title: '国家'},
                {field:'province', title: '省'},
                {field:'city', title: '市'},
                {field:'subscribeStatus', title: '关注状态'},
                {field:'subscribeTime', title: '关注时间'},
                {field:'statusLabel', title: '状态'},
				<%if(shiro.hasPermission("wx:wxAccountFans:edit")){%>
					{title: '操作', width:170, templet:'#wxAccountFansListBar',fixed:"right",align:"center"}
				<%}%>
			]]
    	});

        //搜索【此功能需要后台配合，所以暂时没有动态效果演示】
        $(".search_btn").on("click",function(){
            var pubid = $("#pubid");
            var keyword = $('#keyword');
            var sex = $('#sex');
            table.reload("wxAccountFansListTable",{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: {
                    pubid : pubid.val(),
                    keyword : keyword.val(),
                    sex : sex.val(),
                }
            })
        });

        //添加
        function addWxAccountFans(id){
            var index = layui.layer.open({
                title : "添加粉丝",
                type : 2,
                content : "${ctx}/wx/wxAccountFans/form?id="+id,
                success : function(layero, index){
                    setTimeout(function(){
                        layui.layer.tips('点击此处返回文章列表', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    },500)
                }
            })
            layui.layer.full(index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
            $(window).on("resize",function(){
                layui.layer.full(index);
            })
        }
        $(".addWxAccountFans_btn").click(function(){
            var id = '${wxAccountFans.id}';
            addWxAccountFans(id);
        })

        //同步粉丝
        $(".syncWxAccountFans_btn").click(function(){
            Common.loading('数据同步中，请稍候...');
            var pubid = $("#pubid").val();
            $.post("${ctx}/wx/wxAccountFans/syncWxAccountFans?pubid="+pubid,function(result){
                if(result.code=="0"){
                    layer.msg(result.msg);
                }else{
                    layer.msg("同步失败");
                }
                tableIns.reload();
                $(".search_btn").click();
            });
        })

        //批量删除
        $(".delAll_btn").click(function(){
            var checkStatus = table.checkStatus('wxAccountFansListTable'),
                data = checkStatus.data,
                selectedIds = [];
            if(data.length > 0) {
                for (var i in data) {
                    selectedIds.push(data[i].id);
                }
                layer.confirm('确定删除选中的数据？', {icon: 3, title: '提示信息'}, function (index) {
                    $.post("${ctx}/wx/wxAccountFans/batchDelete",{selectedIds:selectedIds.join(",")},function(result){
                        if(result.code=="0"){
                            layer.msg(result.msg);
                        }else{
                            layer.msg("删除失败");
                        }
                        tableIns.reload();
                        layer.close(index);
                    });
                })
            }else{
                layer.msg("请选择需要删除的数据");
            }
        })

        //列表操作
        table.on('tool(wxAccountFansList)', function(obj){
            var layEvent = obj.event,
                data = obj.data;

            if(layEvent === 'sendMessage'){ //发送信息
                layer.confirm('确定发送信息？',{icon:3, title:'提示信息'},function(index){
                    $.post("${ctx}/wx/wxAccountFans/sendMessage",{openId:data.openId},function(result){
                        if(result.code=="0"){
                            layer.msg("发送成功");
                        }else{
                            layer.msg("发送失败");
                        }
                        tableIns.reload();
                        layer.close(index);
                    });
                });
            } else if(layEvent === 'del'){ //删除
                layer.confirm('确定删除此文章？',{icon:3, title:'提示信息'},function(index){
                    $.post("${ctx}/wx/wxAccountFans/delete",{id:data.id},function(result){
                        if(result.code=="0"){
                            layer.msg("删除成功");
                        }else{
                            layer.msg("删除失败");
                        }
                        tableIns.reload();
                        layer.close(index);
                    });
                });
            } else if(layEvent === 'look'){ //预览
                layer.alert("此功能需要前台展示，实际开发中传入对应的必要参数进行文章内容页面访问")
            }
        });

    })
</script>
<%}%>